<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script src="js/jquery-3.7.1.min.js"></script>
<h1>注册</h1>
<form id="regForm">
  用户名：<input type="text" placeholder="请输入用户名" name="username"><br>
  密码：<input type="text" placeholder="请输入密码" name="password"><br>
    确认密码：<input type="text" placeholder="请确认密码" name="password2"><br>
  <button id="loginBut" type="button">注册</button>
</form>

<script>
    $(function (){
        $('#loginBut').on('click',function (){
            //serialize序列化查询参数
            let data=$('#regForm').serialize();

            $.post('reg',data,function (resp){
                if (resp.code === 1){
                    // location.href="index.html";
                }else {
                    alert(resp.msg)
                }
            });
        })
    })
</script>
</body>
</html>